<?php

namespace core;

class Config
{
    // 存放配置信息的数组
    public $config = [];

    public $defaultConfig;

    public function __construct()
    {
        $this->defaultConfig = require '../config/config.php';
        $this->loadConfigFiles();
    }

    public function getConfig()
    {
        return $this->config;
    }

    /**
     * 加载配置文件
     */
    private function loadConfigFiles()
    {
        $this->config = $this->defaultConfig;

        // 其余配置文件非空，一起加载进来
        if ($this->defaultConfig['config_files'] != '') {
            $configFiles = explode(',', $this->defaultConfig['config_files']);

            foreach ($configFiles as $kCfg => $vCfg) {
                $this->config = array_merge($this->config, require '../config/' . $vCfg . '.php');
            }
        }
    }
}
